<?php 
namespace Home\Controller;
use Think\Controller;
class ScheduleController extends Controller{
	
	private $workTime=array(
		'start' => '8:00',
		'end'	=> '22:00'
	);
	
	private $timeList = array(
			'1:00','2:00','3:00','4:00','5:00','6:00','7:00',
			'8:00','9:00','10:00','11:00','12:00',
			'13:00','14:00','15:00','16:00','17:00','18:00',
			'19:00','20:00','21:00','22:00',
			'23:00','24:00',
	);
	private $timeList2 = array(
			
			'8:00','9:00','10:00','11:00','12:00',
			'13:00','14:00','15:00','16:00','17:00','18:00',
			'19:00','20:00','21:00','22:00'
			
	);
		
	//设置上班时间
	   public function ScheduleManage(){
	   			$schedule = D('Schedule');
	   	  if(IS_AJAX){	   	  		
		   	  	if($_POST['mark']=='wTime'){
		     	    $uid=I('post.id');     	   
		     	    $workTime=I('post.workTime');
		     		$CurrentDate=I('post.currentDate');
		     		$CurrentDate=date('Y-m-d');	     		
		     		$row = $schedule->where("CurrentDate='$CurrentDate'")->find();
		     		if($row['workTime']!='') {
		     			$new_workTime = $row['workTime'].",".$workTime;
		     			$sql = "replace into mdd_schedule values ('$new_workTime','$CurrentDate',$uid)";
		     			$schedule->execute($sql);exit;		     		
		     		}     			     	
		     		$sql = "replace into mdd_schedule(workTime,CurrentDate,uid) values ('$workTime','$CurrentDate',$uid)";
		     		$schedule->execute($sql);
		   	  	}
	   	   } else {	   	  
	   	   	//查询上班时间
			   	   	$uid='1';
			   	   	$result = $schedule->where("uid=$uid")->order('CurrentDate')->select();
			   	   	$this->$currentDResult=$result[0]['CurrentDate'];			   	   	
			   	   	//$today = strtotime('Y-m-d'.$this->time['start']);			   	    
			   	   	$workTime = array_map(function ($var) {
			   	   		return explode(',', $var['workTime']);
			   	   	}, $result);			   	   	
			   	   	$workResult=$result[0]['workTime'];			   	   	
			   	   	$this->$Tdata=explode(',',$workResult);		
			   	   	$this->assign('timeList', $this->timeList);//时间值
			   	 //  	$this->assign('timeList2', $this->timeList2);//时间值
			   	   	$this->assign('timeSetting', $workTime);//插入的值
	   	   	        $this->display();	   	   	     	   	   		
	   	   }	   	     	    
	   	}	  
}